Skip to content

Conditional return type for SQLite3Result::fetchArray()#3080

Merged
staabm merged 1 commit intophpstan:2.1.xfrom
devnix:database-non-empty-results-2
May 1, 2026
Merged

Conditional return type for SQLite3Result::fetchArray()#3080
staabm merged 1 commit intophpstan:2.1.xfrom
devnix:database-non-empty-results-2

Conversation

@devnix
Copy link
Copy Markdown
Contributor

@devnix devnix commented May 16, 2024

I'm aware that this change can be wrong or incomplete. I was wondering if there is a way in this project to do tests for types, for example https://github.com/azjezz/psl/blob/next/tests/static-analysis

@ondrejmirtes
Copy link
Copy Markdown
Member

You mean tests for types? Sure: https://phpstan.org/developing-extensions/testing#type-inference

Here most of them are in NodeScopeResolverTest.

@VincentLanglet
Copy link
Copy Markdown
Contributor

Hi @devnix, are you still interested by this PR ? If so, please now target 2.1.x instead. Thanks

@devnix devnix changed the base branch from 1.11.x to 2.1.x April 30, 2026 06:57
Comment thread resources/functionMap.php Outdated
@devnix devnix force-pushed the database-non-empty-results-2 branch from 106d4b6 to ee87b7e Compare April 30, 2026 07:37
@devnix devnix requested a review from staabm April 30, 2026 07:40
Copy link
Copy Markdown
Contributor

@VincentLanglet VincentLanglet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a similar return type possible for fetchAll ?
https://github.com/JetBrains/phpstorm-stubs/blob/34a487bd374e42f4ce58606473d1b6882bfec2b7/sqlite3/sqlite3.php#L642
(will need to be in php85delta since it was introduced in php 8.5).

Also might be worth to add fetchArray has having sideEffect to avoid something like
https://phpstan.org/r/7281fb29-1861-4297-8c50-4a708cbebf1c

@devnix devnix force-pushed the database-non-empty-results-2 branch from ee87b7e to 13e7254 Compare April 30, 2026 14:04
@devnix
Copy link
Copy Markdown
Contributor Author

devnix commented Apr 30, 2026

Is a similar return type possible for fetchAll ? https://github.com/JetBrains/phpstorm-stubs/blob/34a487bd374e42f4ce58606473d1b6882bfec2b7/sqlite3/sqlite3.php#L642 (will need to be in php85delta since it was introduced in php 8.5).

Also might be worth to add fetchArray has having sideEffect to avoid something like https://phpstan.org/r/7281fb29-1861-4297-8c50-4a708cbebf1c

Great catch @VincentLanglet, done!

@@ -0,0 +1,31 @@
<?php // php >= 8.5
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<?php // php >= 8.5
<?php // lint >= 8.5

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, fixed 🤦🏼‍♂️

@devnix devnix force-pushed the database-non-empty-results-2 branch from 13e7254 to 65f55ab Compare April 30, 2026 14:34
@devnix devnix requested a review from VincentLanglet April 30, 2026 14:40
@staabm
Copy link
Copy Markdown
Contributor

staabm commented May 1, 2026

thank you

@staabm staabm merged commit c10c01d into phpstan:2.1.x May 1, 2026
656 of 659 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants